require "./src/lyristal.cr"
require "option_parser"

artist = ""
song = ""

OptionParser.parse do |parser|
    parser.banner = "lyristal example usage"
    parser.on("-a ARTIST", "--artist=ARTIST", "specify song artist") { |a| artist = a}
    parser.on("-n NAME", "--name=NAME", "specify song name") { |n| song = n }
    parser.on("-h", "--help", "show this") do
        puts parser
        exit
    end
end

if artist == "" || song == ""
    puts "Artist or song name not specified."
    exit
end 

lyristal = Lyristal::AZLyrics.new
lyricsPageResponse = lyristal.getLyricsPage(artist, song)
if lyricsPageResponse[:code] == 200
    puts "Found lyrics URL: #{lyricsPageResponse[:url]}"
else
    puts "Got code #{lyricsPageResponse[:code]} in response, is the artist and song title spelt correctly?"
    exit
end
lyrics = lyristal.scrapeLyrics(lyricsPageResponse[:url])
puts "Fetched lyrics:"
puts lyrics